﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ChonDe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
            Response.Redirect("dangnhap.aspx");
        if (!IsPostBack) {
            loadDeThi();
            loadThongTinHocVien();
            loadDeDaThi();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
    public void loadDeThi() {
        int mahv = int.Parse(Session["user"].ToString());
        DataTable dsDethi = BaiThiDAL.DanhSachDeThi(mahv);
        if (dsDethi.Rows.Count <= 0) { 
            mess.Text = "<div class='alert alert-danger'>Không có để thi nào</div>";
        }
        GridView1.DataSource = dsDethi;
        GridView1.DataBind();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "BatDau")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            Session["BaiThi"] = index;
            Response.Redirect("default.aspx");
        }
    }

    public void loadThongTinHocVien()
    {
        int mahv = int.Parse(Session["user"].ToString());
        HocVienINFO mHocVien = HocVienDAL.GetInfo(mahv);
        lblHoTen.Text = mHocVien.TenHV;
        lblNgaySinh.Text = mHocVien.NgaySinh.ToString("dd/MM/yyyy");
        lblDiaChi.Text = mHocVien.DiaChi;
        lblDienThoai.Text = mHocVien.SDT;
        lblEmail.Text = mHocVien.Email;
    }

    public void loadDeDaThi()
    {
        int mahv = int.Parse(Session["user"].ToString());
        DataTable dsDeDaThi = BaiThiDAL.DanhSachDeDaThi(mahv);
        dsDaThi.DataSource = dsDeDaThi;
        dsDaThi.DataBind();
    }
}